package com.sjf.batch.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * @author <huangtang>
 * @since 2022/1/13 17:12
 **/
@Configuration
public class RedissionConfig {

    @Bean(value = "redissonClient")
    RedissonClient redisson () {
        Config config = new Config ();
        config.useSingleServer ()
                .setAddress ("redis://47.108.147.215:6379")
                .setPassword ("1314520abc");

        return Redisson.create (config);
    }

    /**
     * Redis 消息监听器容器.
     *
     * @param redisConnectionFactory the redis connection factory
     * @return the redis message listener container
     */
    @Bean
    public RedisMessageListenerContainer redisMessageListenerContainer ( RedisConnectionFactory redisConnectionFactory ) {
        RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer ();
        redisMessageListenerContainer.setConnectionFactory (redisConnectionFactory);
        return redisMessageListenerContainer;
    }

}
